package swordoffer.offer41;

import java.util.ArrayList;

/**
 * 暴力解
 */
public class BruteSolution {
    class MedianFinder {
        private ArrayList<Integer> list;

        /**
         * initialize your data structure here.
         */
        public MedianFinder() {
            this.list = new ArrayList<>();
        }

        public void addNum(int num) {
            list.add(num);
        }

        public double findMedian() {
            list.sort((a, b) -> (a - b));
            int size = list.size();
            if ((size & 1) == 0) {
                return (list.get(size / 2) + list.get((size / 2) - 1)) / 2.0;
            } else {
                return (double) list.get(size / 2);
            }
        }
    }
}
